{
	template:`
	<a-page-header title="关联用户">
		<template #extra>
			<a-button type="primary" @click="save();">保存</a-button>
			<m-back @click="back(false);">关闭</m-back>
		</template>
		<a-card :bodyStyle="{padding:'0 20px'}" :hoverable="true">
			<a-row>
				<a-col :span="8">
					<div style="max-height:500px;overflow-y:auto;overflow-x:hidden;">
						<a-tree :tree-data="dataList" v-model:selected-keys="selectKey" @select="selectTree"></a-tree>
					</div>
				</a-col>
				<a-col :span="11">
					<div style="max-height:500px;overflow-y:auto;overflow-x:hidden;">
						<a-list size="small">
							<a-list-item>
								<a-input-search v-model:value="searchTxt" placeholder="搜索..." :allowClear="true" @search="searchUser"/>
							</a-list-item>
                            <a-list-item v-for="item in allData">
                                <a-checkbox v-model:checked="selectMap[item.oid]" @change="doCheck(item)">
                                <span style="min-width:90px;display:inline-block;">{{item.realname}}</span>
                                <span style="padding-left:10px;min-width:120px;display:inline-block;">{{item.username}}</span>
                                <span>{{item.adminGroup.name}}</span>
                                </a-checkbox>
                            </a-list-item>
                            <a-list-item>
                                <a-pagination v-model:current="pageno" simple :total="count" @change="searchUser"/>
                            </a-list-item>
                            <a-list-item v-if="allData.length==0">
                                暂无用户
                            </a-list-item>
						</a-list>
					</div>
				</a-col>
				<a-col :span="5">
					<div style="max-height:500px;overflow-y:auto;overflow-x:hidden;">
						<div style="padding-top:10px;"><b>已选:</b></div>
						<template v-for="item in allLink">
						<a-tag style="margin:10px 0 0 10px;" v-if="selectMap[item.oid]" color="blue" closable @close="removeSelect(item.oid)">{{item.realname}}</a-tag>
						</template>
					</div>
				</a-col>
			</a-row>
		</a-card>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			adminGroupOid:'',
			adminGroup:{},
			typeNames:{'B':'角色','C':'机构'},
			dataList:[
				{oid:'',key:'',type:'',title:'全部'},
				{oid:'B',key:'B',type:'B',title:'角色',children:[]},
				{oid:'C',key:'C',type:'C',title:'机构',children:[]}
			],
			list:[],//机构构建使用
			map:{},//机构构建使用
			selectKey:[''],
			selectItem:null,
			selectMap:{},//{用户oid:boolean}
			allLink:{},
			allData:[],
			searchTxt:'',
            pageno:1,
            count:0,
		};
	},
	mounted(){
		this.selectItem=this.dataList[0];
		this.adminGroupOid=this.param.adminGroupOid;
		this.requestData("action/manage/adminGroup/getList",
			{model:{status:'0'}},
			function(json){
				if(json.code==0){
					for(let i=0;i<json.list.length;i++){
						json.list[i]['key']=json.list[i].oid;
						json.list[i]['title']=json.list[i].name;
						if(json.list[i].type=='A'){

						}else if(json.list[i].type=='B'){
							this.dataList[1].children.push(json.list[i]);
						}else if(json.list[i].type=='C'){
							this.map[json.list[i].oid]=json.list[i];
						}
						if(this.adminGroupOid==json.list[i].oid){
							this.adminGroup=json.list[i];
						}
					}
					this.dataList[2].children=this.list;
					for(let k in this.map){
						let group=this.map[k];
						group['key']=group.oid;
						group['title']=group.name;
						if(group.parent&&group.parent.oid){
							group.render=this.nodeRender;
							let parent=this.map[group.parent.oid];
							if(!parent.children) parent.children=[];
							parent.children.push(group);
						}else{
							this.list.push(group);
						}
					}
				}else{
					this.remind().error(data.msg);
				}
			}.bind(this)
		);
		this.requestData("action/manage/adminGroupLink/getLink",
			{adminGroupOid:this.adminGroupOid},
			function(json){
				if(json.code==0){
					this.allLink=json.allLink;
					for(var k in this.allLink){
					    this.selectMap[k]=true;
					}
					this.searchUser();
				}else{
					this.remind().error(data.msg);
				}
			}.bind(this)
		);
	},
	methods:{
		selectTree:function(selectedKeys, e){
			this.selectItem=e.selectedNodes[0];
			this.pageno=1;
			this.searchUser();
		},
		searchUser:function(){
		    let ps={page:{index:(this.pageno-1)*10,num:10}};
		    ps['realname']=this.searchTxt;
		    if(this.selectItem&&this.selectItem.type){
                if(this.selectItem.type=='B') ps['roleGroup']=this.selectItem.oid;
                if(this.selectItem.type=='C') ps['orgGroup']=this.selectItem.oid;
		    }
            this.requestData("action/manage/adminLogin/getAllAdmin",
                ps,
                function(data){
                    if(data.code==0){
                        this.allData=data.list;
                        this.count=data.count;
                    }else{
                        this.remind().error(data.msg);
                    }
                }.bind(this)
            );
		},
		doCheck:function(user){
		    if(this.selectMap[user.oid]){
		        this.allLink[user.oid]=user;
		    }else{
		        delete this.allLink[user.oid];
		    }
		},
		removeSelect:function(key){
			this.selectMap[key]=false;
		},
		save:function(){
			var adminOids=[];
			for(var i in this.selectMap){
				if(this.selectMap[i]){
					adminOids.push(i);
				}
			}
			this.requestData("action/manage/adminGroupLink/setLink",
				{"adminGroupOid":this.adminGroupOid,"adminOids":adminOids},
				function(data){
					if(data.code!=0){
						this.remind().error(data.msg);
					}else{
						this.remind().success(data.msg);
						this.back(true);
					}
				}.bind(this)
			);
		},
	}
}